//
//  ArrearageViewController.m
//  KD
//
//  Created by Hubery on 15/8/21.
//  Copyright (c) 2015年 centling. All rights reserved.
//

#import "ArrearageViewController.h"
#import "DetailsCellModel.h"
#import "TransactTableViewCell.h"
#import "ExecuteCellModel.h"
#import "DefrayViewController.h"

@interface ArrearageViewController ()

@end

@implementation ArrearageViewController

-(void)viewDidLoad
{
    [super viewDidLoad];
    [self adddata];
}

#pragma mark - UITableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if(section == 1) return 64;
    else return 20;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 1) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)];
        
        UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn1.frame=CGRectMake(10,10,([UIScreen mainScreen].bounds.size.width-20)*0.3, 44);
        [btn1 setTitle:@"拍照" forState: UIControlStateNormal];
        [btn1 setBackgroundColor:[UIColor  redColor]];
        [btn1 addTarget:self action:@selector(btnClick1) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
        btn2.frame=CGRectMake(([UIScreen mainScreen].bounds.size.width-20)*0.3+10,10,([UIScreen mainScreen].bounds.size.width-20)*0.7, 44);
        [btn2 setTitle:@"支付" forState: UIControlStateNormal];
        [btn2 setBackgroundColor:[UIColor  blueColor]];
        [btn2 addTarget:self action:@selector(btnClick2) forControlEvents:UIControlEventTouchUpInside];

        [view addSubview:btn1];
        [view addSubview:btn2];
        return view;
    }
    return nil;
}

#pragma mark - 跳转
-(void)btnClick2
{
    DefrayViewController *vc = [DefrayViewController initWithStoryBoard];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)btnClick1
{
    HXLog(@"我要拍照");
}
#pragma mark - DatePicker监听
-(void)valueChange:(UIDatePicker *)dataPicker
{
    NSDateFormatter *dateF = [[NSDateFormatter alloc]init];
    dateF.dateFormat = @"YYYY-MM-dd";//创建日期格式对象
    HXLog(@"%@",[dateF stringFromDate:dataPicker.date]);
    NSArray *array = self.oddNumberGroup[1];
    ExecuteCellModel *item = [array objectAtIndex:3];
    item.property = [dateF stringFromDate:dataPicker.date];
    [self.tableView reloadData];
}

#pragma mark - 添加假数据
-(void)adddata
{
    DetailsCellModel *item00 = [[DetailsCellModel alloc]initWithIcon:@"666" propertyName:@"aa" property:@"aaa" destClass:nil];
    NSArray *array1 = [NSArray arrayWithObjects:item00,nil];
    [self.oddNumberGroup addObject:array1];
    BaseCellModel *item10 = [[BaseCellModel alloc]initWithIcon:@"666" propertyName:@"海关状态:" property:@"海关放行"];
    DetailsCellModel *item11 = [[DetailsCellModel alloc]initWithIcon:@"666" propertyName:@"货物信息:" property:@"总数:10" destClass:nil];
    DetailsCellModel *item12 = [[DetailsCellModel alloc]initWithIcon:@"666" propertyName:@"支付金额:" property:@"￥10000" destClass:nil];
    ExecuteCellModel *item13 = [[ExecuteCellModel alloc]initWithIcon:@"666" propertyName:@"提货时间" property: @"请选择"];
    item13.option = ^{
        UITextField *textField = [[UITextField alloc]init];
        UIDatePicker *datePicker = [[UIDatePicker alloc]init];
        datePicker.datePickerMode = UIDatePickerModeDate;//设置模式
        datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];//设置地区
        NSDateFormatter *dateF = [[NSDateFormatter alloc]init];
        dateF.dateFormat = @"YYYY:MM:DD";//创建日期格式对象
        //监听datePicker
        [datePicker addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged];
        textField.inputView = datePicker;//创建键盘
        [textField becomeFirstResponder];
        [self.view addSubview:textField];
    };
    NSArray *array2 = [NSArray arrayWithObjects:item10,item11,item12,item13,nil];
    [self.oddNumberGroup addObject:array2];
}
@end